<template>
  <div>
    <div>
      <span>后台首页</span> <span>></span> <span>创建商品</span>
      <el-button size="small"  @click='huiqu'>回到商品列表</el-button>
    </div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="商品名称">
        <el-input
          class="mingcheng"
          v-model="form.title"
          placeholder="请输入商品名称，不能超过60个字符"
        ></el-input>
      </el-form-item>
      <el-form-item label="封面"> </el-form-item>

      <el-form-item label="商品分类">
        <el-select v-model="form.category_id"   placeholder="请选择商品分类">
          <el-option
            :label="item.name"
            v-for="(item) in list"
            :key="item.id"
             :value="item.id"

          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="商品描述">
        <el-input type="textarea" v-model="form.desc" class="miaoshu"></el-input>
      </el-form-item>
      <el-form-item label="商品单位">
        <el-input
          class="danwei"
          v-model="form.unit"
          placeholder="请输入商品单位"
        ></el-input>
      </el-form-item>
      <el-form-item label="总库存">
        <el-input type="Number" v-model="form.stock" class="kucun"></el-input>
        <span class="jian">件</span>
      </el-form-item>
      <el-form-item label="库存预警">
        <el-input type="Number" v-model="form.min_stock" class="kucun"></el-input>
        <span class="jian">件</span>
      </el-form-item>
      <el-form-item label="最低销售价">
        <el-input type="Number" v-model="form.min_price" class="kucun"></el-input>
        <span class="jian">元</span>
      </el-form-item>
      <el-form-item label="最低原价">
        <el-input type="Number" v-model="form.min_oprice" class="kucun"></el-input>
        <span class="jian">元</span>
      </el-form-item>

      <el-form-item label="库存显示">
        <el-radio-group size="qwe"  v-model='form.stock_display' >
          <el-radio border label="1"  >是</el-radio>
          <el-radio border label="0"  >否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否上架">
        <el-radio-group size="qaz"   v-model='form.status' >
          <el-radio border label="0">放入仓库</el-radio>
          <el-radio border label="1">立即上架</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="运费模板">
        <el-select v-model="form.express_id" placeholder="请选择运费模板">
          <el-option
            :label="it.name"
            v-for="(it) in arr"
            :key="it.id" 
             :value="it.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>

    <button class="tijiao" @click="tijiao">提交</button>
  </div>
</template>
<script>
import { getcreate } from "@/api/index";

export default {
  data() {
    return {
      form: {
        title:'',

        category_id:'',
        desc:'',
        unit:'',
        stock:'',
        min_stock:'',
        min_price:'',
        min_oprice:'',
        stock_display:'',
        status:'',
        express_id:''
      },
      list: [],
      arr: [],
    };
  },
  methods: {
    tijiao() {
   
      this.$axios.post("http://ceshi5.dishait.cn/admin/goods", {
        category_id: this.form.category_id,
        cover: '',
        desc:this.form.desc,
        express_id: this.form.express_id,
        ischeck: 0,
        min_oprice: this.form.min_oprice,
        min_price: this.form.min_price,
        min_stock: this.form.min_stock,
        status: this.form.status,
        stock: this.form.stock,
        stock_display: this.form.stock_display,
        title: this.form.title,
        unit: this.form.unit,
      });
    },
    onSubmit() {
      console.log("submit!");
    },
    //获取数据
    async getlist() {
      const res = await getcreate();
      if (res.data.msg == "ok") {
        this.list = res.data.data.cates;
        console.log(this.list);
        this.arr = res.data.data.express.list;
      }
    },
    huiqu(){
                  this.$router.push('/shop/goods/list')
       
    }
  },
  mounted() {
    this.getlist();
  },
};
</script>
<style>
.mingcheng {
  width: 600px;
}
.miaoshu {
  width: 600px;
}
.danwei {
  width: 600px;
}
.kucun {
  width: 200px;
  height: 40px;
}
.jian {
  display: inline-block;
  width: 40px;
  height: 40px;
  font-size: 14px;
  text-align: center;
  background: #ccc;
  line-height: 40px;
}
.tijiao {
  position: fixed;
  bottom: 50px;
  right: 50px;
  cursor: pointer;
  color: #fff;
  background-color: teal;
  border-color: teal;
  padding: 12px 20px;
  font-size: 14px;
  border-radius: 4px;
  border: none;
}
</style>
